home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #27 (Dec 87) / c daisy printer driver / Utils.c < prev    next >
C/C++ Source or Header  |  1987-10-24  |  3KB  |  127 lines

  1. /*
  2.  * Utility program to format the code resources used with the Daisy
  3.  * printing manager.  If you run it twice, it does nothing the second
  4.  * time.
  5.  */
  6. #include    "prglobals.h"
  7. #define    PAD    24L
  8. typedef struct{
  9.     unsigned int    flags;
  10.     unsigned int    delay;
  11.     unsigned int    emask;
  12.     unsigned int    menu;
  13. }driver,*Pdriver,**Hdriver;
  14. void mkDefault();
  15. main()
  16. {
  17.     setpackflags();
  18.     setdriverflags();
  19.     createPDEF("\psrc:Printer:DaisyPDEF0",0);
  20.     createPDEF("\psrc:Printer:DaisyPDEF4",4);
  21.     createPDEF("\psrc:Printer:DaisyPDEF5",5);
  22.     createPREC();
  23. }
  24. /*
  25.  * This is a utility function to strip off the header bytes LightSpeedC
  26.  * puts on Code Resources it creates.  I put an illegal instruction right
  27.  * before the code I want.
  28.  */
  29. createPDEF(filename,idno)
  30. char *filename;
  31. int idno;
  32. {
  33. long         thesize;
  34. unsigned int     **thehandle,**newhandle;
  35. unsigned int    *theword,*newone;
  36. int        thefile;
  37. int        result;
  38.     thefile = OpenResFile(filename);
  39.     thehandle = (unsigned int **) GetResource('pdef',idno);
  40.     if (thehandle == 0L) return;
  41.     else{
  42.         thesize = SizeResource(thehandle) + PAD;
  43.         asm {
  44.             move.l    thehandle,a0
  45.             _HLock
  46.         }
  47.         theword = *thehandle;
  48.         while(*theword++ != ILLEGAL){
  49.             thesize -=2;
  50.         }
  51.         asm{
  52.             move.l    thesize,d0
  53.             _NewHandle
  54.             move.l    a0,newhandle
  55.         }
  56.         if (newhandle == 0L) return;
  57.         else{
  58.             asm{
  59.                 move.l    newhandle,a0
  60.                 _HLock
  61.                 move.l    (a0),newone
  62.                 move.l    theword,a0
  63.                 move.l    newone,a1
  64.                 move.l    thesize,d0
  65.                 _BlockMove
  66.                 move.w    d0,result
  67.             }
  68.             if(result)return;
  69.             AddResource(newhandle,'PDEF',idno,"\pStripped PDEF");
  70.             WriteResource(newhandle);
  71.             RmveResource(thehandle);
  72.             UpdateResFile(thefile);
  73.             CloseResFile(thefile);
  74.         }
  75.     }
  76. }
  77. setdriverflags()
  78. {
  79. Hdriver    Xprint;
  80.     OpenResFile("\psrc:Printer:DaisyDRVR");
  81.     Xprint = (Hdriver)(GetResource('DRVR',2));
  82.     (*Xprint)->flags = dCtlEnable | dStatEnable;
  83.     (*Xprint)->delay = 0x0000;
  84.     (*Xprint)->emask = 0x0000;
  85.     (*Xprint)->menu = 0x0000;
  86.     ChangedResource(Xprint);
  87.     WriteResource(Xprint);
  88. }
  89.     
  90. /* 
  91.  * This function sets the version number and flags for the PACK resource
  92.  * used to interface with the Chooser.
  93.  */
  94. setpackflags()
  95. {
  96. long    **pack;
  97.     OpenResFile("\psrc:Printer:DaisyPACK");
  98.     pack = (long **)(GetResource('PACK',-4096));
  99.     if (pack != 0L){
  100.         *((*pack)+2) = 0xF0000001;
  101.         *((*pack)+3) = 0x0400E000;
  102.         ChangedResource(pack);
  103.         WriteResource(pack);
  104.     }
  105. }
  106. /*
  107.  * Create a default printer settings resource based on the same code used in
  108.  * our printer resource file.
  109.  */
  110. createPREC()
  111. {
  112. THPrint    thehandle;
  113.     CreateResFile("\psrc:Printer:DaisyPREC0");
  114.     OpenResFile("\psrc:Printer:DaisyPREC0");
  115.     SetResLoad(TRUE);
  116.     RmveResource(GetResource('PREC',0));
  117.     asm{
  118.         move.l    #((long)sizeof(TPrint)),d0
  119.         NewHandle
  120.         move.l    a0,thehandle
  121.     }
  122.     mkDefault(thehandle);
  123.     AddResource(thehandle,'PREC',0,"\pPrint defaults");
  124.     WriteResource(thehandle);
  125. }
  126. #include "mkDefault.c"
  127.